<template>
  <div class="permission">
    <div class="custom-tree-container" style="float:left;width:20%;">
      <el-tree
        :data="PermissionParentList"
        show-checkbox
        node-key="id"
        ref="tree"
        highlight-current
        :default-expanded-keys="[1]"
        :default-checked-keys="[1]"
        :props="defaultProps"
        @node-click="handleNodeClick()"
        @check="selectParent"
        style="margin-top: 10px;margin-left: 15px">
      </el-tree>
    </div>
    <div class="app-container" style="float:left;width:80%;border-left:1px solid red">
      <div class="filter-container" style="margin-top: 10px">
        <el-button
          class="filter-item"
          style="margin-left: 10px;"
          type="primary"
          icon="el-icon-edit"
          @click="handleCreate"
        >
          {{ $t('table.add') }}
        </el-button>
      </div>

      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column
          label="序号"
          prop="id"
          align="center"
          width="80"
        >
          <template slot-scope="{row}">
            <span>{{ row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="名称" align="center">
          <template slot-scope="{row}">
            <span>{{ row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="描述" align="center">
          <template slot-scope="{row}">
            <span>{{ row.desc }}</span>
            <!--          <el-tag>{{ row.type | typeFilter }}</el-tag>-->
          </template>
        </el-table-column>
        <el-table-column label="请求方式" align="center">
          <template slot-scope="{row}">
            <!--          <span>{{ row.author }}</span>-->
            <!--          <span>{{ row.author }}</span>-->
            <span>{{ row.method }}</span>
          </template>
        </el-table-column>

        <el-table-column label="接口地址">
          <template slot-scope="{row}">
            <!--          <svg-icon v-for="n in +row.importance" :key="n" icon-class="star" class="meta-item__icon" />-->
            <span>{{ row.api_route }}</span>
          </template>

        </el-table-column>
        <el-table-column label="状态" class-name="status-col">
          <template slot-scope="{row}">
            <el-tag :type="row.status | statusFilter">
              {{ row.status  | statusText }}
            </el-tag>

          </template>
        </el-table-column>
        <el-table-column :label="$t('table.actions')" align="center" min-width="70"
                         class-name="small-padding fixed-width">
          <template slot-scope="{row,$index}">
            <el-button type="primary" size="mini" @click="handleUpdate(row)">
              {{ $t('table.edit') }}
            </el-button>

            <el-button v-if="row.status!='deleted'" size="mini" type="danger" @click="handleDelete(row,$index)">
              {{ $t('table.delete') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
        <el-form
          ref="dataForm"
          :rules="rules"
          :model="temp"
          label-position="left"
          label-width="90px"
          style="width: 400px; margin-left:50px;"
        >
          <el-form-item label="父级id" prop="parentid">
            <el-input v-model.number="temp.parentid" type="number"/>
          </el-form-item>

          <el-form-item label="名称" prop="name">
            <el-input v-model="temp.name"/>
          </el-form-item>

          <el-form-item label="api路径" prop="api_route">
            <el-input v-model="temp.api_route"/>
          </el-form-item>

          <el-form-item label="web路径" prop="web_route">
            <el-input v-model="temp.web_route"/>
          </el-form-item>

          <el-form-item label="请求方式" prop="method">
            <el-input v-model="temp.method"/>
          </el-form-item>

          <el-form-item label="描述" prop="desc">
            <el-input v-model="temp.desc"/>
          </el-form-item>

          <el-form-item label="控制器" prop="controller">
            <el-input v-model="temp.controller"/>
          </el-form-item>

          <el-form-item label="方法" prop="function">
            <el-input v-model="temp.functions"/>
          </el-form-item>

          <el-form-item label="权限验证" prop="is_system_menu">
            <el-input v-model="temp.is_need_auth"/>
          </el-form-item>

          <el-form-item label="是否菜单" prop="is_system_menu">
            <el-input v-model="temp.is_system_menu"/>
          </el-form-item>


          <!--          <el-form-item :label="$t('table.importance')">-->
          <!--            <el-rate-->
          <!--              v-model="temp.importance"-->
          <!--              :colors="['#99A9BF', '#F7BA2A', '#FF9900']"-->
          <!--              :max="3"-->
          <!--              style="margin-top:8px;"-->
          <!--            />-->
          <!--          </el-form-item>-->

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">
            {{ $t('table.cancel') }}
          </el-button>
          <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
            {{ $t('table.confirm') }}
          </el-button>
        </div>
      </el-dialog>

      <el-dialog :visible.sync="dialogPvVisible" title="Reading statistics">
        <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
          <el-table-column prop="key" label="Channel"/>
          <el-table-column prop="pv" label="Pv"/>
        </el-table>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogPvVisible = false">{{ $t('table.confirm') }}</el-button>
      </span>
      </el-dialog>
    </div>

  </div>
</template>

<script src="./_permission.js" lang="js"></script>
<style src="./_permission.scss" lang="scss" scoped></style>
